/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.srcptit.trainning.thompv.btvn2;
import java.util.Scanner;
/**
 *
 * @author SONY
 */
public class Bai11 {
    public static String inputString()
    {
        Scanner sc=new Scanner(System.in);
        String s=null;
        int stop=1;
        System.out.println("\tNhap 1 xau String: ");
        while(stop==1)
        {
            try
            {
                s=sc.nextLine();
                if(s.length()<1) throw new Exception("Xau rong! Nhap lai:");
                stop=0;
                System.out.println("OK! Ban nhap dung! ");
            }
            catch (Exception e)
            {
                System.out.println("error !!!" +e);
            }
        }
        return null;
    }
    public static int inputInt()
    {
        Scanner sc=new Scanner(System.in);
        int n=0,stop=1;
        String s;
        System.out.println("\tNhap so kieu Integer: ");
        while(stop==1)
        {
           try
           {
               s=sc.nextLine();
               if(s.length()<1) throw new Exception("Xau rong ");
               n=Integer.parseInt(s);
               stop=0;
               System.out.println("OK! Ban nhap dung!");
           }
           catch (Exception e)
           {
               System.out.println("error !!!" +e);
           }
        }
       return n; 
    }
    public static float inputFloat()
    {
        Scanner sc=new Scanner(System.in);
        Float n=null;
        String s;
        int stop=1;
        System.out.println("\tNhap 1 so kieu float: ");
        while(stop==1)
        {
            try
            {
                s=sc.nextLine();
                if(s.length()<1) throw new Exception("Xau rong ");
                n=Float.parseFloat(s);
                stop=0;
                System.out.println("OK! Ban nhap dung! ");
            }
            catch (Exception e)
            {
               System.out.println("error !!! "+e);
            }
        }
        return n;
    }
    public static double inputDouble()
    {
        Scanner sc=new Scanner(System.in);
        Double n=null;
        String s;
        int stop=1;
        System.out.println("\tNhap 1 so kieu Double: ");
        while(stop==1)
        {
           try
           {
               s=sc.nextLine();
               if(s.length()<1) throw new Exception("Xau rong ");
               n=Double.parseDouble(s);
               stop=0;
               System.out.println("OK! Ban nhap dung!");  
           }
           catch (Exception e)
           {
               System.out.println("error !!! "+e);
           } 
        }
        return n;
    }
    public static void main(String[] args) 
    {
        inputString();
        inputInt();
        inputFloat();
        inputDouble();
    }
}
